package com.serviceImpl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.entity.Category;
import com.mapper.ArticleMapper;
import com.mapper.CategoryMapper;
import com.service.CategoryService;
/**
 * 
 * @author MingCha Yang
 *
 */
@Service("categoryServiceImpl")
public class CategoryServiceImpl implements CategoryService{

	@Resource
	private CategoryMapper categoryMapper;
	@Resource
	private ArticleMapper articleMapper;
	
	@Override
	public List<Category> getCategoryList() {
		List<Category> categorys = categoryMapper.getCategoryList();
		for (Category category : categorys) {
			category.setArticleCount(articleMapper.getCountsBycategoryId(category.getCategoryId()));
		}
		return categorys;
	}

	@Override
	public List<Category> getCategorylistByCategoryPid(Integer articleParentCategoryId) {
		
		return categoryMapper.getCategorylistByCategoryPid(articleParentCategoryId);
	}

	@Override
	public void addCategory(Category category) {
		categoryMapper.addCategory(category);
		
	}

	@Override
	public void deletCategoryBycategoryId(Integer categoryId) {
		categoryMapper.deletCategoryBycategoryId(categoryId);
		
	}

	@Override
	public void updateCategoryBycategoryId(Category category) {
		categoryMapper.updateCategoryBycategoryId(category);
		
	}

	@Override
	public Category getCategoryBycategoryId(Integer categoryId) {
		
		return categoryMapper.getCategoryBycategoryId(categoryId);
	}

	@Override
	public void deletCategoryBycategoryPid(Integer categoryPid) {
		categoryMapper.deletCategoryBycategoryPid(categoryPid);
		
	}

}
